<template>
  <div class="renting">
    <header>
      <div class="header-one">
        <span @click="goback">
          <van-icon name="arrow-left" />
        </span>
        <span>租房</span>
        <span>
          <van-icon name="more-o" />
        </span>
      </div>
      <div class="header-two">
        <div class="search">
          <div class="option">
            <span @click="anchor">
              {{this.name}}
              <a-icon type="caret-down" />
            </span>
          </div>
          <div class="input">
            <input type="text" placeholder="请在这里输入区域/商圈" />
            <van-icon name="search" class="icon" />
          </div>
          <span>地图找房</span>
        </div>
        <div class="hint">
          <div>
            <span>
              <img src="../imges/11.png" alt />
            </span>
            <span>找商铺</span>
          </div>
          <div>
            <span>
              <img src="../imges/12.png" alt />
            </span>
            <span>找写字楼</span>
          </div>
          <div>
            <span>
              <img src="../imges/13.png" alt />
            </span>
            <span>找小区</span>
          </div>
        </div>
      </div>
      <div class="header-three">
        <li @click="area">
          区域
          <a-icon type="caret-down" />
        </li>
        <li @click="price">
          价格
          <a-icon type="caret-down" />
        </li>
        <li @click="house">
          户型
          <a-icon type="caret-down" />
        </li>
        <li @click="screen">
          筛选
          <a-icon type="caret-down" />
        </li>
        <li>
          <i class="el-icon-sort-down" @click="rank()"></i>
          <i class="el-icon-sort-up" @click="rank1()"></i>
        </li>
      </div>
    </header>
    <main>
      <div class="main">
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
          <div class="main_list" v-for="(item,index) in list" :key="index">
            <div class="detail">
              <img :src="item.img1" alt @click="detail(item.id)" />
              <div class="main-one">
                <p>{{item.word}}</p>
                <p>
                  <span>{{item.type}}</span>&emsp;
                  <span>{{item.citys}}</span>&emsp;
                  <span>{{item.screen}}</span>
                </p>
                <p>
                  <span class="price">{{item.price}}万</span>&emsp;
                  <span class="money">12100元/m²</span>
                </p>
                <p>
                  <button>小区</button>
                </p>
              </div>
            </div>
          </div>
        </van-pull-refresh>
      </div>
    </main>
  </div>
</template>

<script>
import { Toast } from "vant";
import axios from "axios";
export default {
  data() {
    return {
      select: "区域",
      option: [
        { text: "区域", value: "区域" },
        { text: "附近", value: "附近" },
        { text: "地铁", value: "地铁" },
        { text: "上海", value: "上海" },
        { text: "北京", value: "北京" },
        { text: "江苏", value: "江苏" }
      ],
      list: [],
      count: 0,
      isLoading: false,
      select1: "价格",
      option1: [
        "价格",
        "不限",
        "≤10万",
        "20万-30万",
        "30万-50万",
        "50万-100万",
        "≥1000万"
      ],
      select2: "户型",
      option2: [
        { text: "户型", value: "户型" },
        { text: "不限", value: "不限" },
        { text: "新房", value: "新房" },
        { text: "二手房", value: "二手房" },
        { text: "不限", value: "不限" },
        { text: "1室", value: "1室" },
        { text: "2室", value: "2室" },
        { text: "3室", value: "3室" },
        { text: "4室", value: "4室" }
      ],
      select3: "筛选",
      option3: [
        { text: "筛选", value: "筛选" },
        { text: "不限", value: "不限" },
        { text: "安选", value: "安选" },
        { text: "南北", value: "南北" },
        { text: "东", value: "东" },
        { text: "西", value: "西" },
        { text: "南", value: "南" },
        { text: "北", value: "北" }
      ]
    };
  },
  created() {
    this.getlist();
    this.getadd();
  },
  methods: {
    //返回上一页
    goback() {
      this.$router.go(-1);
    },
    //获取数据
    getlist() {
      axios({
        url: "/api/lists",
        method: "get"
      }).then(res => {
        this.list = res.data.data;
      });
    },

    //下拉刷新
    onRefresh() {
      setTimeout(() => {
        Toast("刷新成功");
        this.isLoading = false;
      }, 500);
    },
    //跳转到描点
    anchor() {
      this.$router.push("/anchor");
    },
    //跳转详情
    detail(id) {
      this.$router.push(`/detail/` + id);
    },
    area(select) {
      axios({
        url: "/api/area",
        method: "post",
        data: {
          select: select
        }
      }).then(res => {
        this.list = res.data.data;
      });
    },
    area2(select2) {
      axios({
        url: "/api/area2",
        method: "post",
        data: {
          select2: select2
        }
      }).then(res => {
        this.list = res.data.data;
      });
    },

    area3(select3) {
      axios({
        url: "/api/area3",
        method: "post",
        data: {
          select3: select3
        }
      }).then(res => {
        this.list = res.data.data;
      });
    },
    rank() {
      this.list.sort((a, b) => {
        return a.price - b.price;
      });
    },
    rank1() {
      this.list.sort((a, b) => {
        return b.price - a.price;
      });
    },
    area() {
      this.$router.push("/area");
    },
    price() {
      this.$router.push("/price");
    },
    house() {
      this.$router.push("/house");
    },
    screen() {
      this.$router.push("/screen");
    },
    getadd(item) {
      this.name = localStorage.getItem("name");
    }
  }
};
</script>

<style scoped>
.detail img {
  width: 160px;
  height: 125px;
}
.renting {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
header {
  height: 359px;
  border-bottom: 1px solid #cccccc;
}
.main_list {
  height: 130px;
  margin-left: 30px;
  margin-top: 20px;
}
main {
  flex: 1;
  overflow-y: auto;
}
.header-one {
  height: 128px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 30px;
  font-size: 22px;
  color: #f3f9ff;
  content: "";
  background: linear-gradient(45deg, #0f7ef4, #1988f6, #34a0fd);
}
.header-two {
  height: 183px;
  border-bottom: 1px solid #bcbcbc;
}
.search {
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 10px;
  border-bottom: 1px solid #cccccc;
  color: #9b9b9b;
}
.header-three {
  display: flex;
  height: 49px;
  align-items: center;
  justify-content: space-between;
  padding: 0px 30px;
  color: #999999;
}
.option select {
  background: none;
  border: none;
  outline: none;
}
.option select option {
  background: #82b9f3;
}
.input {
  width: 200px;
  height: 30px;
  border: 1px solid #cccccc;
  display: inline-block;
  background: #f4f4f4;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.input span {
  color: #929292;
}
.input input {
  border: none;
  background: none;
  outline: none;
}
.input .icon {
  color: #9c9c9c;
  font-weight: bold;
  font-size: 20px;
}
.hint {
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 20px;
}
.detail {
  display: flex;
}
.main-one {
  margin-left: 10px;
}
.main-one button {
  width: 50px;
  height: 20px;
  border: none;
}
.price {
  color: orange;
  font-weight: bold;
}
</style>